<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.crossriver.crgis.database.model.Application_C_of_O"%>
<%@page import="com.crossriver.crgis.database.service.Application_C_of_OLocalServiceUtil"%>
<%@page import="com.liferay.portal.service.LayoutLocalServiceUtil"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="/init.jsp"%>





<div id="main">
 	<h1>Requests</h1>
 	<%
    ThemeDisplay themeDisp = (ThemeDisplay) request
    .getAttribute(WebKeys.THEME_DISPLAY);

      String userId = ""+themeDisp.getUserId();

      User workingUser = UserLocalServiceUtil.getUser(themeDisp.getUserId());
 	
 	%>
 	
 	<div class="content"> 
 		
        	<p>Welcome, <strong>
        	<%=workingUser.getLastName() %>, 
        	<%=workingUser.getFirstName() %>
        	<%=workingUser.getMiddleName() %> </strong>!
   		Here, you can view the request status and request details of different
  		  	applications being processed by the Ministry of Lands and Housing.</p>
   		<p>We indulge you to see that all applications are duly approved and
   		all pending processes are completed if you have not met the required
   		conditions.</p>
   		
   		<p>Please note that Payments can be made for applications with SUBMITTED status. Payments can be made at our office, through this portal or directly at any branch of the lead bank. </p>
   		
   		<p>You may Click on the status condition of your application to view
   		more details. </p>
      <table width="100%" align="center" id="tb-1">
       	<tbody><tr class="title">
                <td width="13%">Application</td>
                <td width="16%">Application Type</td>
                <td width="12% ">Date Started</td>
                <td width="12%">Date Submitted</td>
                <td width="29%">Reference Number</td>
                <td width="13%">Status</td>
                <td width="5%">Action</td>
                
       	</tr>
       	
      <%
      
	      
	      List<Application_C_of_O> apps = Application_C_of_OLocalServiceUtil.
      						getApplication_C_of_OByUserId(userId);
	      
	      //eleminate request that are deleted
	      
	      List<Application_C_of_O> copyForDisplay = new ArrayList<Application_C_of_O>();
	      for(int j=0; j<apps.size();j++){
	    	  Application_C_of_O appl = apps.get(j); 
	    	  if(!"DELETED".equalsIgnoreCase(appl.getStatus())){
	    		  copyForDisplay.add(appl);
	    	  }
	      }
      
	      for(int i =0; i<copyForDisplay.size(); i++){
	    	  Application_C_of_O app = copyForDisplay.get(i); 
	    	  
	    	  String status = app.getStatus();
	    	  
	    	  String applicatin = app.getApplication();
	    	  if(applicatin != null) applicatin = applicatin.toUpperCase();
	    	  String applicatin_type = app.getApplicationType();
	    	  if(applicatin_type != null) applicatin_type = applicatin_type.toUpperCase();
	    	  
	    	  DateFormat df = new SimpleDateFormat("dd-MMM-yyyy :mm:ss");
	    	  
	    	  String date_submitted="";
	    	  if(app.getDateOfApplication() != null){
	    		  
	    	  }
	    	  
	    	  
	    	  
	    	  
      %> 	
       	
       	<tr>
                 <td><%=applicatin %></td>
                <td><%=applicatin_type %></td>
                
                <%
                String appStartDate = "";
                if(null != app.getApplicationStartDate() ){
                	//TODO to format this later
                	appStartDate = df.format(app.getApplicationStartDate());
                }
                %>
                <td><%=appStartDate %> </td>
                
                <%
                String dateOfAppl = "";
                if(null != app.getDateOfApplication() ){
                	//TODO to format this later
                	dateOfAppl = df.format(app.getDateOfApplication());
                }
                %>
                <td><%=dateOfAppl %></td>
                
                <td><%=app.getReferenceNo() %></td>
                
                
				<liferay-portlet:actionURL var="viewApplicationDetail">
				  <liferay-portlet:param name="javax.portlet.action" value="viewApplicationDetail"></liferay-portlet:param>
				  <liferay-portlet:param name="applicationId" value="<%= app.getApplicationId() %>">"></liferay-portlet:param>
				</liferay-portlet:actionURL>
				
				<%
				String applicationType = app.getApplicationType();
				String applicationId = app.getApplicationId();
				String __application = app.getApplication();
				long plidRecofo = 0;
				
				if ("certification".equalsIgnoreCase(__application)){
				  plidRecofo = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), true, "/certificate-of-occupancy").getPlid();	
				  
				}else{
					plidRecofo = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), true, "/re-certificate-of-occupancy").getPlid();
					
				}
			 	%>
				
				<liferay-portlet:actionURL var="editTransaction" plid="<%=plidRecofo %>">
				  <portlet:param name="application" value="<%= applicationType %>" />
				  <portlet:param name="fromRequest" value="YES"></portlet:param>
				  <portlet:param name="applicationId" value="<%= app.getApplicationId() %>">"></portlet:param>
				  
				</liferay-portlet:actionURL>
				
				<%
				if("new".equalsIgnoreCase(app.getStatus())){
				%>
				
                <td><a href="<%= editTransaction %>" class="<%= app %>"><%=app.getStatus() %></a></td>
                <%
				}else{
                %>
                <td><a href="<%= viewApplicationDetail %>" class="<%= app %>"><%=app.getStatus() %></a></td>
                <%
				}
                %>
                
                <td>
                
                <%
                if( "NEW".equalsIgnoreCase(app.getStatus())){
                %>
                	<portlet:actionURL name="deleteApplication" var="deleteURL">
						<portlet:param name="applicationId" value="<%=app.getApplicationId()%>" />
					</portlet:actionURL>
					<liferay-ui:icon image="delete" url="<%=deleteURL.toString() %>" />
				                
				<%
                }
				%>

				</td>
       	</tr>
       	<%
	      }
       	%>
       	<!-- 
       	
       	<tr>
                <td>Certificate Of Occupancy</td>
                <td>10-Sep-2010</td>
                <td>CRSG-MLH-2010-100810C</td>
                <td><a href="app-status-approved.htm" class="approved">Approved</a></td>
       	</tr>
            <tr>
                <td>Re-Certificate Of Occupancy</td>
                <td>12-Apr-2011</td>
                <td>CRSG-MLH-2011-120411B</td>
                <td><a href="app-status-stopped.htm" class="stopped">Stopped!</a></td>
       	</tr>       	 -->
       	
     		</tbody></table>
 		</div>
</div>

<script type="text/javascript">
<!--
function confirmPost()
{
var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
if (agree)
return true ;
else
return false ;
}
//-->
</script>

